package cn.zhaoyuening.crm.web.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import cn.zhaoyuening.crm.domain.CrmCourseType;
import cn.zhaoyuening.crm.service.CourseTypeService;
import cn.zhaoyuening.crm.utils.page.PageBean;

public class CourseTypeAction extends BaseAction<CrmCourseType> {
	private CourseTypeService courseTypeService;
	private CrmCourseType courseType = new CrmCourseType();
	

	
	
	/**
	 * show all CrmCourseType 2 Jsp pages
	 * @return
	 */
	public String list(){
		//高级查询
		PageBean<CrmCourseType> pageBean = this.courseTypeService.findAll(this.courseType,getPageNum(),getPageSize());
		//save to valueContext
		ServletActionContext.getContext().put("allCourseTypes", pageBean.getData());
		//总页数
		setTotalPage(pageBean.getTotalPage());
		
		return "list";
	}
	
	/**
	 * show edited courseType
	 * @return
	 */
	public String editUi(){
		//select edited courseType
		this.courseType = courseTypeService.findById(this.courseType.getCourseTypeId());
		return "addOrEditUi";
	}
	
	//add or edit courseType
	public String addOrEdit(){
		boolean isAdd = this.courseTypeService.addOrEdit(this.courseType);
		if (isAdd) {
			addActionMessage("添加课程类别： "+this.courseType.getCourseName()+" 成功");
		}else {
			addActionMessage("编辑课程类别： "+this.courseType.getCourseName()+" 成功");
		}
		//return CourseType list pages
		return list();
	}
	
	
	public void setCourseTypeService(CourseTypeService courseTypeService) {
		this.courseTypeService = courseTypeService;
	}
	
	public CrmCourseType getCourseType() {
		return courseType;
	}
	public void setCourseType(CrmCourseType courseType) {
		this.courseType = courseType;
	}

	
	
}
